/**
 * 
 */
package org.log4jconfig.xml.editor.contentassist.attribute;

import java.util.List;

import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.log4jconfig.xml.editor.utils.ContentAssistRequestUtils;
import org.log4jconfig.xml.editor.utils.JdtUtils;
import org.log4jconfig.xml.editor.utils.Logger;

/**
 * @author Xi
 * 
 */
@SuppressWarnings("restriction")
public class LevelOrPriorityValueContentAssistComputer extends AbstractContentAssistComputer {

	public void addAttributeValueProposals(IJavaProject javaProject, ContentAssistRequest contentAssistRequest,
			String attributeCurrentValue, String attributeMatchValue) throws Exception {
		String tagName = ContentAssistRequestUtils.extractTagName(contentAssistRequest);
		IType type = null;
		if(tagName.equals("level")) {
			type = JdtUtils.getTypeFromCurrentProject(javaProject, "org.apache.log4j.Level");
		} else if(tagName.equals("priority")) {
			type = JdtUtils.getTypeFromCurrentProject(javaProject, "org.apache.log4j.Priority");
		}
		if (type == null) {
			Logger.warn("Could not find type matching the current element name in project's classpath");
			return;
		}
		List<IField> fields = JdtUtils.getStaticFieldsFromType(type);
		for (IField value : fields) {
			addCompletionProposal(contentAssistRequest, value.getElementName(), value.getAttachedJavadoc(null),
					attributeCurrentValue, attributeMatchValue, ISharedImages.IMG_FIELD_PUBLIC);
		}

	}

}
